﻿using System.ComponentModel;
using System.Windows.Media;

namespace System.Windows.Controls
{
    /// <summary>
    /// A class to define a sector on the gauge scale
    /// A range is used to indicate some significance
    /// in the corresponding scale range
    /// </summary>
    public class RangeDefinition : FrameworkContentElement,INotifyPropertyChanged
    {
        private static readonly DependencyProperty MaxProperty = DependencyProperty.Register("Max", typeof (double),
                                                                                   typeof(RangeDefinition), new PropertyMetadata(1.0, OnPropertyChanged));


        private static readonly DependencyProperty MinProperty = DependencyProperty.Register("Min", typeof (double),
                                                                                   typeof(RangeDefinition), new PropertyMetadata(0.0, OnPropertyChanged));


        private static readonly DependencyProperty StrokeProperty = DependencyProperty.Register("Stroke", typeof (Brush),
                                                                                          typeof(RangeDefinition), new PropertyMetadata(null, OnPropertyChanged));


        private static readonly DependencyProperty ThicknessProperty = DependencyProperty.Register("Thickness", typeof (int),
                                                                                         typeof(RangeDefinition), new PropertyMetadata(20, OnPropertyChanged));
        /// <summary>
        /// The max limit of the range as percentage of full scale
        /// </summary>
        public double Max
        {
            get { return (double) GetValue(MaxProperty); }
            set { SetValue(MaxProperty, value); }
        }
        /// <summary>
        /// The minimum of the range as percentage of full scale
        /// </summary>
        public double Min
        {
            get { return (double) GetValue(MinProperty); }
            set { SetValue(MinProperty, value); }
        }
        /// <summary>
        /// The color of the range
        /// </summary>
        public Brush Stroke
        {
            get { return (Brush)GetValue(StrokeProperty); }
            set { SetValue(StrokeProperty, value); }
        }
        /// <summary>
        /// The height of the range
        /// </summary>
        public int Thickness
        {
            get { return (int) GetValue(ThicknessProperty); }
            set { SetValue(ThicknessProperty, value); }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = (o, e) => { };

        #endregion

        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var definition = (RangeDefinition) d;
            definition.PropertyChanged(d,new PropertyChangedEventArgs(e.Property.Name));
        }
    }
}